<html>
<head>
    <meta charset="utf-8">
    <title>帖子详情 - 数媒贴吧</title>
    <link rel="stylesheet" href="/statics/css/index.css">
    <link rel="stylesheet" href="/statics/css/common.css">
    <link rel="stylesheet" href="/statics/css/detail.css">
</head>
<body>
<?php require_once './Views/common/header.tpl.php'?>
<div class="box">
    <div class="left">
        <div class="post-box">
            <div class="post-detail-title"><?php echo $post['title']?></div>
            <div class="post-detail-content">
                <?php echo $post['content'];?>
            </div>
        </div>
        <?php if (isset($_SESSION['user_id']) && isset($_SESSION['username'])):?>
        <div class="comment-form">
            <form action="">
                <input type="hidden" name="post_id" value="<?php echo $post['id'];?>">
                <div class="comment-form-item"><textarea name="content" placeholder="填写评论内容"></textarea></div>
                <div class="comment-form-item"><input type="submit" value="发表评论"></div>
            </form>
        </div>
        <?php endif;?>
        <div class="comment">
            <h3>主题评论</h3>
            <div class="comment-list">
                <?php foreach($commentList as $val):?>
                <div class="comment-item">
                    <div class="comment-info">
                        <div class="comment-info-left"><span class="username"><?php echo $val['username']?></span><span class="publish-time"><?php echo $val['created_at'];?></span></div>
                        <div class="comment-info-right"><a href="javascript:evaluate_comment(1, <?php echo $val['id'];?>)">赞（<?php echo $val['praise_count'];?>）</a> <a href="javascript:evaluate_comment(2, <?php echo $val['id'];?>)">踩（<?php echo $val['step_count'];?>）</a></div>
                    </div>
                    <div class="clear"></div>
                    <div class="comment-content"><?php echo $val['content'];?></div>
                </div>
                <?php endforeach;?>
            </div>
        </div>
    </div>
    <?php require_once './Views/common/right.tpl.php';?>
</div>
<div class="clear"></div>
<?php require_once './Views/common/footer.tpl.php';?>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script>
    jQuery(function() {
        jQuery('form').submit(function() {
            var params = jQuery('form').serialize();
            jQuery.post('/index.php?c=comment&a=add', params, function(data) {
                if (data.status == 200) {
                    alert('评价成功');
                    window.location.reload()
                } else {
                    alert(data.message);
                }
            }, 'json');
            return false;
        });
    })

    function evaluate_comment(type, comment_id) {
        var params = {
            type: type,
            comment_id: comment_id
        };
        jQuery.post('/index.php?c=comment&a=evaluate', params, function(data) {
            if (data.status == 200) {
                alert('评价成功');
                window.location.reload()
            } else {
                alert(data.message);
            }
        }, 'json');
    }
</script
</body>
</html>